package com.s64.controller;

import com.s64.entity.SysUser;
import com.s64.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/users")
@CrossOrigin
public class UserController {

    @Autowired
    private IUserService userService;

    @GetMapping
    public Page<SysUser> getAll(int pageNo, int pageSize) {
        return userService.getAll(PageRequest.of(pageNo - 1, pageSize));
    }

    @GetMapping("/del")
    public boolean del(Integer id) {
        return userService.del(id) > 0;
    }

    @GetMapping("/update/{id}")
    public SysUser update(@PathVariable Integer id) {
        return userService.get(id);
    }

    @PostMapping("/update")
    public boolean update(SysUser user) {
        userService.update(user);
        return true;
    }

    @PostMapping("/add")
    public boolean add(SysUser user) {
        userService.add(user);
        return true;
    }
}
